// pages/mingzi/mingzi.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    region: ['上海市', '上海市', '黄浦区'],
    now_region:['上海市','上海市','黄浦区'],
    id :wx.getStorageSync('id')
  },
  formSubmit: function(e) {
    var warn = "";//弹框时提示的内容
    var flag = true;//判断信息输入是否完整
    //判断的顺序依次是：姓名-手机号-地址-具体地址-预约日期-预约时间-开荒面积
    if (e.detail.value.name == "") {
      warn = "请填写您的姓名！";
    } else if (e.detail.value.tel == "") {
      warn = "请填写您的手机号！";
    } else if (!(/^1(3|4|5|7|8)\d{9}$/.test(e.detail.value.phone))) {
      warn = "手机号格式不正确";
    } else if (e.detail.value.city == '') {
      warn = "请选择您的地址"
    } else if (e.detail.value.nowcity == "") {
      warn = "请输入您的具体地址";
    } else if (e.detail.value.date == '') {
      warn = "请选择出生日期";
    } else if (e.detail.value.time == '') {
      warn = "请选择出生时间";
    } else if (e.detail.value.work == '') {
      warn = "请输入您的职业";
    } else if (e.detail.value.fname == '') {
      warn = "请输入父名";
    } else if (e.detail.value.mname == '') {
      warn = "请输入母名";
    } else if (e.detail.value.sex == '') {
      warn = "请选择您的性别";
    } else if (e.detail.value.zlname == '') {
      warn = "请填写资料名称";
    } else {
      flag = false;//若必要信息都填写，则不用弹框，且页面可以进行跳转
      wx.request({
        url: 'https://wx.gjzy.com/weixin/Admin/Index/mingzi',
        data: {
          zlname:e.detail.value.zlname,
          userid: e.detail.value.userid,
          typ: e.detail.value.type,
          name: e.detail.value.name,
          sex: e.detail.value.sex,
          ceng: e.detail.value.ceng,
          xi  : e.detail.value.xi,
          ji  : e.detail.value.ji,
          date: e.detail.value.date,
          time: e.detail.value.time,
          city: e.detail.value.city,
          nowcity: e.detail.value.nowcity,
          work: e.detail.value.work,
          phone: e.detail.value.phone,
          email: e.detail.value.email,
          fname: e.detail.value.fname,
          fdate: e.detail.value.fdate,
          ftime: e.detail.value.ftime,
          mname: e.detail.value.mname,
          mdate: e.detail.value.mdate,
          mtime: e.detail.value.mtime
        },
        method:'POST',
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        success: function (res) {
          console.log(res)
          if (res.data == 200) {
            wx.showToast({
              title: "成功",
              icon: 'success',
              duration: 3000,
              success: function () {
                wx.redirectTo({
                  url: '/pages/zl/zl',
                })
              }
            })
          } else {
            wx.showToast({
              title: "失败",
              icon: 'none',
              duration: 3000,
              success: function () {
                wx.redirectTo({
                  url: '/pages/zl/zl',
                })
              }
            })
          }
        }
      })
      console.log('form发生了submit事件，携带数据为：', e.detail.value)
    }
    //如果信息填写不完整，弹出输入框
    if (flag == true) {
      wx.showModal({
        title: '提示',
        content: warn
      })
    }
  },
  formReset: function() {
    console.log('form发生了reset事件')
  },
  // 以下为页面日期时间改变触发时间
  bindDateChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value
    })
  },
  bindFDateChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      Fdate: e.detail.value
    })
  },
  bindMDateChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      Mdate: e.detail.value
    })
  },
  bindTimeChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      time: e.detail.value
    })
  },
  bindFTimeChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      Ftime: e.detail.value
    })
  }, bindMTimeChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      Mtime: e.detail.value
    })
  },
  // end
  bindRegionChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      region: e.detail.value
    })
  },
  bindRegionChange_new: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      now_region: e.detail.value
    })
  },
  url2:function(){
    wx.redirectTo({
      url: '../zl/zl',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})